﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Eksponent.CropUp.Config
{
    public class CropInfoElement : ConfigurationElement
    {       
        [ConfigurationProperty("alias", IsRequired = true)]
        public string Alias
        {
            get { return (string)this["alias"]; }
            set { this["alias"] = value; }
        }

        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }

        [ConfigurationProperty("width", IsRequired = true)]
        public int Width
        {
            get { return int.Parse(""+this["width"]); }
            set { this["width"] = ""+value; }
        }

        [ConfigurationProperty("height", IsRequired = true)]
        public int Height
        {
            get { return int.Parse(""+this["height"]); }
            set { this["height"] = "" + value; }
        }      
    }

    public class CropInfoCollection : ConfigurationElementCollection
    {
        public CropInfoElement this[int index]
        {
            get { return BaseGet(index) as CropInfoElement; }
            set
            {                
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new CropInfoElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((CropInfoElement) element).Alias;
        }
    }
}
